// Copyright (C) 2022 Linlexiao
#include "fureferencewidget.h"

#include <QHeaderView>
#include <QTableWidgetItem>

#define SET(i, j, s)                                     \
    {                                                    \
        QTableWidgetItem* it = new QTableWidgetItem(#s); \
        it->setTextAlignment(Qt::AlignCenter);           \
        this->setItem(i, j, it);                         \
    }

FuReferenceWidget::FuReferenceWidget(QWidget* parent) : QTableWidget(parent) {
    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
    setRowCount(7);
    setColumnCount(9);
    horizontalHeader()->hide();
    verticalHeader()->hide();
    setStyleSheet("*{font: 12pt 微软雅黑}");
    SET(0, 0, 听牌);
    SET(2, 0, 门清荣和);
    SET(2, 1, +10符);
    SET(3, 0, 自摸和);
    SET(3, 1, +2符);
    SET(4, 0, 嵌张);
    SET(5, 0, 边张);
    SET(6, 0, 单骑);

    SET(0, 2, 雀头);
    SET(2, 2, 客风);
    SET(2, 3, 0符);
    SET(3, 2, 自风);
    SET(3, 3, +2符);
    SET(4, 2, 场风);
    SET(5, 2, 三元);
    SET(6, 2, 连风);
    SET(6, 3, +4符);

    SET(0, 4, 面子);
    SET(1, 4,\\);
    SET(2, 4, 顺子);
    SET(2, 5, 0符);
    SET(3, 4, 明刻);
    SET(3, 5, +2符);
    SET(3, 6, +4符);
    SET(4, 4, 暗刻);
    SET(4, 5, +4符);
    SET(4, 6, +8符);
    SET(5, 4, 明杠);
    SET(5, 5, +8符);
    SET(5, 6, +16符);
    SET(6, 4, 暗杠);
    SET(6, 5, +16符);
    SET(6, 6, +32符);
    SET(1, 5, 中张);
    SET(1, 6, 幺九);

    SET(0, 7, 特殊);
    SET(2, 7, 符底);
    SET(2, 8, 20符);
    SET(3, 7, 七对子荣和);
    SET(4, 7, 七对子自摸);
    SET(3, 8, = 25符);
    SET(5, 7, 平和自摸);
    SET(5, 8, = 20符);
    SET(6, 7, 副露后20符);
    SET(6, 8, = 30符);

    setSpan(0, 0, 2, 2);
    setSpan(3, 1, 4, 1);

    setSpan(0, 2, 2, 2);
    setSpan(3, 3, 3, 1);

    setSpan(0, 4, 1, 3);
    setSpan(2, 5, 1, 2);

    setSpan(0, 7, 2, 2);
    setSpan(3, 8, 2, 1);

    //    setSpan(7,0,2,9);
    //    SET(7,1,符底：和牌就有的符\t连风：东场时东家的东，南场时南家的南\n符数合计之后，各位0舍1入(例：22符=30符，30符=30符))

    setSelectionMode(QAbstractItemView::NoSelection);
    setEditTriggers(QAbstractItemView::NoEditTriggers);

    horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
    horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
    horizontalHeader()->setSectionResizeMode(7, QHeaderView::ResizeToContents);
    horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
    verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
    verticalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    verticalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
}

QSize FuReferenceWidget::sizeHint() const { return {620, 250}; }
